<template>
	<!-- 登录界面 -->
	<view>
		<view class="logo">
			<image src="../../static/login/logo.png"></image>
		</view>
		<view class="image">
			<text>登录</text>
		</view>
		<!-- 用户操作 -->
		<view class="inputValue">
			<!-- 用户名 -->
			<view class="username">
				<input type="text" value="" v-model="username" placeholder="请输入用户名" />
			</view>
			<!-- 密码 -->
			<view class="userpass">
				<input   :type="flaga" value="" v-model="password" placeholder="请输入密码" />
				<image @click="flags" src="../../static/login/icon-item2.png" mode=""></image>
			</view>
			<!-- 注册or忘记密码 -->
			<view class="register">
				<view class="">
					<text class="register-text" @click="zhuce">立即注册</text>
				</view>
				<view class="">
					<text class="register-password">忘记密码</text>
				</view>
			</view>
			<!-- 点击登录 -->
			<view class="BtnLogin">
				<button type="default" @tap="login">登录</button>
			</view>
		</view>
		<!-- 其他登录方式 -->
		<view class="loginMethod">
			<!-- 标题 -->
			<view class="loginMethod-title">
				<view class="loginMethod-title-span">

				</view>
				<view class="loginMethod-title-val">
					<text>其他登录方式</text>
				</view>
				<view class="loginMethod-title-span">

				</view>
			</view>
			<!-- 其他登录方式 -->
			<view class="OtherLogin">
				<view class="">
					<image src="../../static/login/icon1.png" mode=""></image>
				</view>
				<view class="">
					<image src="../../static/login/icon2.png" mode=""></image>
				</view>
				<view class="">
					<image src="../../static/login/icon3.png" mode=""></image>
				</view>
				<view class="">
					<image src="../../static/login/icon4.png" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: "18784430061", //用户名
				password: "123456", //密码
				flaga:"password", //密码显示或隐藏
			}
		},
		methods: {
			// 登录
			async login() {
				const res = await this.$request({
					url: "/member/login",
					method: "POST",
					data: {	
							"password": this.password,
							"username": this.username
					}
				})
				if(res.code==200){
					console.log(res)
					// 保存token
					uni.setStorage({
						key:"token",
						data:res.data.token
					})
					// 保存用户信息
					getApp().globalData.userInfo = res.data;
					// 跳转到首页
					uni.switchTab({
						url:"/pages/home/home"
					})
					// 给用户信息消息
					uni.showToast({
						title:"登录成功",
						icon:"success"
					})
				}else{
					uni.showToast({
						title:"登录失败",
						icon:"error"
					})
				}
			},
			zhuce(){
				uni.navigateTo({
					url:"/pages/register/register"
				})
			},
			// 控制密码的显示或者隐藏
			flags(){
				if(this.flaga=="password"){
					this.flaga  = "text"
					
				}else{
					this.flaga  = "password"
				}
			}
		}
	
	}
</script>

<style scoped lang="scss">
	@import './login.scss'
</style>
